package todo;

import done.AbstractWashingMachine;

public class WashingProgram2 extends WashingProgram {

	protected WashingProgram2(AbstractWashingMachine mach, double speed,
			TemperatureController tempController,
			WaterController waterController, SpinController spinController) {
		super(mach, speed, tempController, waterController, spinController);
	}

	@Override
	protected void wash() throws InterruptedException {
		myMachine.setLock(true);
		//Förtvätt 
		
		myWaterController.putEvent(new WaterEvent(this, 1, 1));

		mailbox.doFetch();
		
		myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_IDLE, 0.0));

		mailbox.doFetch();
		
		
		mySpinController.putEvent(new SpinEvent(this, 1));
		mailbox.doFetch();
				
		myTempController.putEvent(new TemperatureEvent(this, 1, 40));
		mailbox.doFetch();
		
		
		sleep(15*60*1000);
		System.out.println("Done förtvätt");
		
		myTempController.putEvent(new TemperatureEvent(this, TemperatureEvent.TEMP_IDLE, 0));
		mailbox.doFetch();
		
		mySpinController.putEvent(new SpinEvent(this, SpinEvent.SPIN_OFF));
		mailbox.doFetch(); 
		
		myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_DRAIN, 0));
		mailbox.doFetch();
		
		myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_IDLE, 0.0));
		mailbox.doFetch();
		
		
		
		
		//Från Prog1
		
		myWaterController.putEvent(new WaterEvent(this, 1, 1));

		mailbox.doFetch();//Vänta på full?
		System.out.println("Ack");
		
		myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_IDLE, 0.0));

		mailbox.doFetch();//Vänta på idle
		
		
		mySpinController.putEvent(new SpinEvent(this, 1));
		mailbox.doFetch();
				
		myTempController.putEvent(new TemperatureEvent(this, 1, 90));
		mailbox.doFetch();
		System.out.println("Ack2");
		
		
		sleep(1800000);
		System.out.println("Done wash part 1");
		// Drain
		
		
		myTempController.putEvent(new TemperatureEvent(this, TemperatureEvent.TEMP_IDLE, 0));
		mailbox.doFetch();
		
		mySpinController.putEvent(new SpinEvent(this, SpinEvent.SPIN_OFF));
		mailbox.doFetch(); //
		
		myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_DRAIN, 0));
		mailbox.doFetch();
		
		myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_IDLE, 0.0));
		mailbox.doFetch();
		
		
		

		for (int i = 0; i < 5; i++) {
			System.out.println("Rinsing...");
			myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_FILL, 1));
			mailbox.doFetch();
			myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_IDLE, 0.0));
			mailbox.doFetch();
			//Spinn on?
			sleep(2*60*1000);//Sov 2 min
			myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_DRAIN, 0.0));
			mailbox.doFetch(); //Tomt
									
			myWaterController.putEvent(new WaterEvent(this, WaterEvent.WATER_IDLE, 0.0));
			mailbox.doFetch();
			
			
		}
		
		//Centrifuge
		mySpinController.putEvent(new SpinEvent(this, SpinEvent.SPIN_FAST));
		sleep(5*60*1000);
		mySpinController.putEvent(new SpinEvent(this, SpinEvent.SPIN_OFF));
		myMachine.setLock(false);
		System.out.println("Done!");
		
		
		
		
		
		
		
		
		

	}

}
